/**
 * zmn文章模块-文章编辑
 * 文件命名格式：zmn.模块.表/功能.jas
 * @author heguanghua
 * @date 2018/10/18
 */
layui.define(['form', 'layedit', 'laydate'], function () {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var layedit = layui.layedit;
    var laydate = layui.laydate;

    // 分类下拉框联动
    zmnOmsPage.laySelectLinkage(form, "/common/news/category/listChilds.action", "categOneId", "categTwoId", "categId");

    form.render(null, "zmn-news-form");

    // 自定义验证规则
    form.verify({
        title: function(value){
            if(value.length < 5){ return "文章标题不能少于5个字符"; };
        }
    });

    // 提交
    form.on('submit(zmn-news-form-submit)', function(obj){
        var data = obj.field;
        var url = "/news/addEdit.action";
        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(json) {
                layer.msg(json.message);
                if(json.status == 200 && data.newsId == 0) {
                    zmnPage.direct("/news/detail.action?newsId=" + json.id, 0);
                }
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){}
        })
        if(data.newsId * 1 > 0) {
            return false;
        }
    });
});